#encoding:UTF-8
#_*_ coding:utf-8 _*_
import hashlib

#用于完整性检查
integrity_check = ('time','v','api','data','sign');
#用于计算md5
md5_scr = ('time','v','api','data')



def check(dict):
    #测试
    return True
    m2 = hashlib.md5()
    #先用map检查是否所有的值都存在,再用reduce合并
    had_all = reduce(lambda x,y : x and y ,map(lambda x : dict.has_key(x),integrity_check))
    if not had_all:
        return False
    #
    map(lambda x:m2.update(x),map(lambda x:dict[x],md5_scr));

    md5v= m2.hexdigest()
    return cmp(dict['sign'],md5v) == 0


if __name__ == '__main__':
    #data={"mobile":"13456761961","password":"123"}&time=123456&v=1.0&api=login.htm&sign=ed183007108f476343a9dbaa42f3bd4e
    dict={}
    dict['data']='{"mobile":"13456761961","password":"123"}';
    dict['time']='123456'
    dict['v']='1.0'
    dict['api']='login.htm'
    dict['sign']='ed183007108f476343a9dbaa42f3bd4e'
    print check(dict)

    print dir(hashlib.md5())